<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>htpasswd 密码生成工具</title>
    <link href="https://cdn.bootcdn.net/ajax/libs/font-awesome/6.7.2/css/all.min.css" rel="stylesheet">
    <link href="./common.css" rel="stylesheet">
    <style>
        /* 基础样式和变量 */
        :root {
            --primary-color: #4a6fa5;
            --secondary-color: #6c8ebd;
            --background-color: #f5f7fa;
            --card-background: #ffffff;
            --text-color: #333333;
            --border-color: #e0e0e0;
            --error-color: #e74c3c;
            --success-color: #2ecc71;
            --shadow-color: rgba(0, 0, 0, 0.1);
            --font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            --tip-background: #e3f2fd;
            --match-highlight: #ffeb3b;
            --match-highlight-dark: #ffc107;
        }

        /* 暗黑模式变量 */
        [data-theme="dark"] {
            --primary-color: #5b8ad6;
            --secondary-color: #7fa3d7;
            --background-color: #1a1a2e;
            --card-background: #222438;
            --text-color: #e0e0e0;
            --border-color: #444444;
            --shadow-color: rgba(0, 0, 0, 0.3);
            --tip-background: #1a2a3a;
            --match-highlight: var(--match-highlight-dark);
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: var(--font-family);
            background-color: var(--background-color);
            color: var(--text-color);
            line-height: 1.6;
            transition: background-color 0.3s, color 0.3s;
        }

        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px;
            min-height: 100vh;
            display: flex;
            flex-direction: column;
        }

        /* 头部样式 */
        header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 30px;
            padding-bottom: 15px;
            border-bottom: 1px solid var(--border-color);
        }

        header h1 {
            font-size: 2rem;
            color: var(--primary-color);
        }

        /* 主内容区域 */
        main {
            flex: 1;
            display: flex;
            gap: 20px;
        }

        .main-content {
            flex: 2;
            display: flex;
            flex-direction: column;
            gap: 20px;
        }

        .sidebar {
            flex: 1;
            max-width: 300px;
        }

        .htpasswd-section {
            background-color: var(--card-background);
            border-radius: 8px;
            box-shadow: 0 4px 6px var(--shadow-color);
            padding: 20px;
            transition: background-color 0.3s, box-shadow 0.3s;
        }

        .htpasswd-section h2 {
            margin-bottom: 15px;
            color: var(--primary-color);
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .htpasswd-section h2 i {
            font-size: 1.2rem;
        }

        .input-group {
            margin-bottom: 15px;
        }

        .input-group label {
            display: block;
            margin-bottom: 5px;
            font-weight: bold;
            color: var(--text-color);
        }

        .input-group input,
        .input-group select,
        .input-group textarea {
            width: 100%;
            padding: 10px;
            border: 1px solid var(--border-color);
            border-radius: 4px;
            font-family: 'Consolas', monospace;
            font-size: 14px;
            background-color: var(--card-background);
            color: var(--text-color);
            transition: border-color 0.3s, background-color 0.3s, color 0.3s;
            resize: vertical;
        }

        .input-group input:focus,
        .input-group select:focus,
        .input-group textarea:focus {
            outline: none;
            border-color: var(--primary-color);
        }

        .button-group {
            display: flex;
            gap: 10px;
            margin-top: 15px;
        }

        .generate-button,
        .copy-button {
            padding: 10px 20px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 14px;
            display: flex;
            align-items: center;
            gap: 5px;
            transition: background-color 0.3s, transform 0.1s;
            height: fit-content;
        }

        .generate-button {
            background-color: var(--primary-color);
            color: white;
        }

        .copy-button {
            background-color: var(--secondary-color);
            color: white;
        }

        .generate-button:hover {
            background-color: var(--secondary-color);
        }

        .copy-button:hover {
            background-color: var(--primary-color);
        }

        .generate-button:active,
        .copy-button:active {
            transform: scale(0.98);
        }

        .result-area {
            min-height: 120px;
        }

        .result-area textarea {
            min-height: 120px;
        }

        .error-message {
            color: var(--error-color);
            font-style: italic;
        }

        .success-message {
            color: var(--success-color);
            font-weight: bold;
        }

        /* 侧边栏样式 */
        .sidebar-section {
            background-color: var(--card-background);
            border-radius: 8px;
            box-shadow: 0 4px 6px var(--shadow-color);
            padding: 20px;
            margin-bottom: 20px;
            transition: background-color 0.3s, box-shadow 0.3s;
        }

        .sidebar-section h3 {
            margin-bottom: 15px;
            color: var(--primary-color);
            font-size: 1.1rem;
        }

        .tool-links {
            list-style: none;
        }

        .tool-links li {
            margin-bottom: 10px;
        }

        .tool-links a {
            display: flex;
            align-items: center;
            gap: 8px;
            color: var(--text-color);
            text-decoration: none;
            padding: 8px 12px;
            border-radius: 4px;
            transition: background-color 0.3s, color 0.3s;
        }

        .tool-links a:hover {
            background-color: var(--tip-background);
            color: var(--primary-color);
        }

        .ad-placeholder {
            background: linear-gradient(45deg, #f0f0f0, #e0e0e0);
            border: 2px dashed #ccc;
            border-radius: 8px;
            padding: 40px 20px;
            text-align: center;
            color: #999;
            font-style: italic;
        }

        [data-theme="dark"] .ad-placeholder {
            background: linear-gradient(45deg, #333, #444);
            border-color: #555;
            color: #777;
        }

        /* 复制通知 */
        .copy-notification {
            position: fixed;
            bottom: 20px;
            right: 20px;
            background-color: var(--success-color);
            color: white;
            padding: 10px 20px;
            border-radius: 4px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
            transform: translateY(100px);
            opacity: 0;
            transition: transform 0.3s, opacity 0.3s;
        }

        .copy-notification.show {
            transform: translateY(0);
            opacity: 1;
        }

        /* 页脚样式 */
        /* 头部控件区域 */
        .header-controls {
            display: flex;
            align-items: center;
            gap: 15px;
        }

        /* 分享按钮 */
        .share-button {
            display: flex;
            align-items: center;
            gap: 8px;
            padding: 2px 6px;
            background-color: var(--secondary-color);
            color: white;
            border-radius: 15px;
            cursor: pointer;
            font-size: 14px;
            transition: background-color 0.3s, transform 0.1s;
        }

        .share-button:hover {
            background-color: var(--primary-color);
        }

        .share-button:active {
            transform: scale(0.98);
        }

        .share-button i {
            font-size: 16px;
        }

        /* 主题切换开关 */
        .theme-toggle {
            position: relative;
        }

        .theme-switch {
            opacity: 0;
            position: absolute;
        }

        .theme-switch-label {
            display: flex;
            align-items: center;
            justify-content: space-between;
            cursor: pointer;
            width: 50px;
            height: 26px;
            background-color: #83d8ff;
            border-radius: 100px;
            position: relative;
            transition: background-color 0.3s;
            padding: 0 5px;
        }

        .theme-switch:checked + .theme-switch-label {
            background-color: #4a4e69;
        }

        .theme-switch-label .fa-sun {
            color: #f39c12;
        }

        .theme-switch-label .fa-moon {
            color: #f1c40f;
        }

        .theme-switch-label .slider {
            position: absolute;
            width: 22px;
            height: 22px;
            border-radius: 50%;
            transition: 0.3s;
            background-color: white;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
            left: 2px;
        }

        .theme-switch:checked + .theme-switch-label .slider {
            transform: translateX(24px);
        }

        /* 隐私提示框样式 */
        .privacy-notice {
            margin-bottom: 20px;
            animation: fadeIn 0.5s ease-in-out;
        }

        .privacy-notice-content {
            display: flex;
            align-items: center;
            background-color: var(--tip-background);
            border-left: 4px solid #2196f3;
            padding: 15px;
            border-radius: 4px;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
            position: relative;
        }

        .privacy-notice-content i.fa-shield-alt {
            font-size: 20px;
            color: #2196f3;
            margin-right: 15px;
        }

        .privacy-notice-content p {
            flex: 1;
            margin: 0;
            font-size: 14px;
            color: var(--text-color);
        }

        .close-notice {
            background: none;
            border: none;
            color: #90a4ae;
            cursor: pointer;
            font-size: 16px;
            padding: 5px;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: color 0.2s;
        }

        .close-notice:hover {
            color: #546e7a;
            background: none;
        }

        @keyframes fadeIn {
            from {
                opacity: 0;
                transform: translateY(-10px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        /* 响应式设计 */
        @media (max-width: 1024px) {
            main {
                flex-direction: column;
            }

            .sidebar {
                max-width: none;
                order: -1;
            }

            .button-group {
                flex-direction: column;
            }

            .generate-button,
            .copy-button {
                width: 100%;
                justify-content: center;
            }
        }

        @media (max-width: 768px) {
            .privacy-notice-content {
                flex-direction: column;
                text-align: center;
                padding: 15px 10px;
            }
            
            .privacy-notice-content i.fa-shield-alt {
                margin-right: 0;
                margin-bottom: 10px;
            }
            
            .close-notice {
                position: absolute;
                top: 5px;
                right: 5px;
            }

            header {
                flex-direction: column;
                gap: 15px;
                text-align: center;
            }
        }
    </style>
    <script type="text/javascript" charset="UTF-8" src="https://cdn.wwads.cn/js/makemoney.js" async></script>
</head>
<body>
    <header>
        <div class="header-container">
            <div class="header-left">
                <div class="logo">
                    <span><a href="https://geekdaxue.co/" target="_blank"><img src="https://geekdaxue.co/static/images/logo_platypus.png" height="30px"></a></span>
                </div>
                <nav class="main-navigation">
                    <div class="nav-item dropdown">
                        <a href="#" class="nav-link">
                            JSON工具 <i class="fas fa-chevron-down"></i>
                        </a>
                        <div class="dropdown-menu">
                            <a href="../json/index.html">JSON 格式化</a>
                            <a href="../json/parser.html">JSON 格式校验</a>
                            <a href="../json/excel.html">JSON 转 Excel/CSV</a>
                            <a href="../json/jsonxml.html">JSON 与 XML 转换</a>
                            <a href="../json/editor.html">JSON 编辑器</a>
                        </div>
                    </div>
                    <div class="nav-item dropdown">
                        <a href="#" class="nav-link">
                            编码转换 <i class="fas fa-chevron-down"></i>
                        </a>
                        <div class="dropdown-menu">
                            <a href="../coding/base64.html">Base64 编码</a>
                            <a href="../coding/urlencoding.html">URL 编码</a>
                            <a href="../coding/md5.html">MD5 加密</a>
                            <a href="../coding/unicode.html">Unicode 转换</a>
                            <a href="../coding/hex_convert.html">进制转换</a>
                        </div>
                    </div>
                    <div class="nav-item dropdown">
                        <a href="#" class="nav-link">
                            文本工具 <i class="fas fa-chevron-down"></i>
                        </a>
                        <div class="dropdown-menu">
                            <a href="../txt/diff.html">文本对比</a>
                            <a href="../txt/replace.html">文本替换</a>
                            <a href="../txt/remove.html">空白行移除</a>
                            <a href="../txt/cn_trans.html">繁简体转换</a>
                        </div>
                    </div>
                    <div class="nav-item dropdown">
                        <a href="#" class="nav-link">
                            图片工具 <i class="fas fa-chevron-down"></i>
                        </a>
                        <div class="dropdown-menu">
                            <a href="../img/2svg.html">图片转 SVG</a>
                            <a href="../img/qr_code.html">二维码生成</a>
                            <a href="../img/barcode.html">条形码生成</a>
                        </div>
                    </div>
                </nav>
            </div>
            <div class="header-controls">
                <div class="theme-toggle">
                    <input type="checkbox" id="theme-switch" class="theme-switch">
                    <label for="theme-switch" class="theme-switch-label">
                        <i class="fas fa-sun"></i>
                        <i class="fas fa-moon"></i>
                        <span class="slider"></span>
                    </label>
                </div>
                <div class="share-button" id="share-button" title="分享给朋友">
                    <i class="fas fa-share-alt"></i>
                    <span>分享</span>
                </div>
            </div>
        </div>
    </header>
    <div class="container">    
        <div id="privacy-notice" class="privacy-notice">
            <div class="privacy-notice-content">
                <i class="fas fa-shield-alt"></i>
                <p>安全提示：您的数据仅在本地浏览器中处理，不会上传到服务器，请放心使用！</p>
                <button id="close-notice" class="close-notice" title="关闭提示">
                    <i class="fas fa-times"></i>
                </button>
            </div>
        </div>
        
        <main>
            <div class="main-content">
                <div class="htpasswd-section">
                    <h2><i class="fas fa-user"></i> 用户信息</h2>
                    <div class="input-group">
                        <label for="username">用户名：</label>
                        <input type="text" id="username" placeholder="请输入用户名">
                    </div>
                    <div class="input-group">
                        <label for="password">密码：</label>
                        <input type="password" id="password" placeholder="请输入密码">
                    </div>
                </div>
                
                <div class="htpasswd-section">
                    <h2><i class="fas fa-cog"></i> 加密设置</h2>
                    <div class="input-group">
                        <label for="algorithm">加密算法：</label>
                        <select id="algorithm">
                            <option value="plain">plain (Windows & TPF servers)</option>
                            <option value="crypt">Crypt (all Unix servers)</option>
                            <option value="md5" selected>MD5 (Apache servers only)</option>
                            <option value="sha1">SHA-1 (Netscape-LDIF / Apache servers)</option>
                        </select>
                    </div>
                    <div class="button-group">
                        <button id="generate-button" class="generate-button">
                            <i class="fas fa-key"></i> 生成密码
                        </button>
                        <button id="copy-button" class="copy-button">
                            <i class="fas fa-copy"></i> 复制结果
                        </button>
                    </div>
                </div>
                
                <div class="htpasswd-section">
                    <h2><i class="fas fa-file-alt"></i> 生成结果</h2>
                    <div class="input-group result-area">
                        <label for="result-output">htpasswd 格式：</label>
                        <textarea id="result-output" readonly placeholder="点击生成密码按钮查看结果..."></textarea>
                    </div>
                </div>
            </div>
            
            <div class="sidebar">
                <div class="sidebar-section">
                    <div class="wwads-cn wwads-vertical" data-id="321" style="max-width:200px"></div>
                </div>

                <div class="sidebar-section">
                    <h3><i class="fas fa-lightbulb"></i> 算法说明</h3>
                    <div style="font-size: 14px; line-height: 1.6; color: var(--text-color);">
                        <p><strong>plain:</strong> 明文存储，适用于 Windows 和 TPF 服务器</p>
                        <p><strong>Crypt:</strong> Unix 标准加密，兼容所有 Unix 服务器</p>
                        <p><strong>MD5:</strong> Apache 专用 MD5 加密，最常用</p>
                        <p><strong>SHA-1:</strong> 适用于 Netscape-LDIF 和 Apache 服务器</p>
                    </div>
                </div>
                
                <div class="sidebar-section">
                    <h3><i class="fas fa-tools"></i> 其他工具</h3>
                    <ul class="tool-links">
                        <li><a href="../json/index.html"><i class="fas fa-code"></i> JSON 工具</a></li>
                        <li><a href="uuid.html"><i class="fas fa-key"></i> UUID 生成器</a></li>
                        <li><a href="base64.html"><i class="fas fa-lock"></i> Base64 编解码</a></li>
                        <li><a href="md5.html"><i class="fas fa-fingerprint"></i> MD5 加密</a></li>
                        <li><a href="timestamp.html"><i class="fas fa-clock"></i> 时间戳转换</a></li>
                        <li><a href="urlencoding.html"><i class="fas fa-link"></i> URL 编解码</a></li>
                        <li><a href="unicode.html"><i class="fas fa-globe"></i> Unicode 转换</a></li>
                        <li><a href="regex.html"><i class="fas fa-search"></i> 正则表达式测试</a></li>
                        <li><a href="guid.html"><i class="fas fa-hashtag"></i> GUID 生成器</a></li>
                    </ul>
                </div>
            </div>
        </main>
    </div>

    <footer>
            <div class="footer-container">
                <div class="footer-main">
                    <div class="footer-section about-us">
                        <h3>关于我们</h3>
                        <p>我们提供一系列高效、便捷的在线工具，帮助开发者、非技术人员提高工作效率，解决日常开发中遇到的各种问题。</p>
                        <p>Build With <i class="fa-solid fa-heart" style="color: red;"></i> For SF.</p>
                    </div>
                    <div class="footer-section links">
                        <h3>工具导航</h3>
                        <div class="links-columns">
                            <ul>
                                <li><a href="../json/index.html">JSON 工具</a></li>
                                <li><a href="../img/index.html">图片处理</a></li>
                                <li><a href="#">开发工具</a></li>
                            </ul>
                            <ul>
                                <li><a href="../coding/index.html">编码转换</a></li>
                                <li><a href="../txt/index.html">文本工具</a></li>
                            </ul>
                        </div>
                    </div>
                    <div class="footer-section contact">
                        <h3>联系我们</h3>
                        <div class="social-icons">
                            <a href="#" title="GitHub"><i class="fab fa-github"></i></a>
                            <a href="#" title="Twitter"><i class="fab fa-twitter"></i></a>
                            <a href="#" title="WeChat"><i class="fab fa-weixin"></i></a>
                            <a href="mailto:example@example.com" title="Email"><i class="fas fa-envelope"></i></a>
                        </div>
                        <p>如有问题或建议，请随时联系我们</p>
                    </div>
                </div>
                <div class="footer-bottom">
                    <p>© 2025 JSON 格式化工具 Pro. 保留所有权利</p>
                    <div class="footer-legal">
                        <a href="#">使用条款</a>
                        <a href="#">隐私政策</a>
                    </div>
                </div>
            </div>
        </footer>
    
    <div id="copy-notification" class="copy-notification">已复制到剪贴板！</div>
    <div id="share-notification" class="copy-notification">已复制网址，赶快让更多的小伙伴知道我吧！</div>
    
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            // 获取DOM元素
            const usernameInput = document.getElementById('username');
            const passwordInput = document.getElementById('password');
            const algorithmSelect = document.getElementById('algorithm');
            const generateButton = document.getElementById('generate-button');
            const copyButton = document.getElementById('copy-button');
            const resultOutput = document.getElementById('result-output');
            const copyNotification = document.getElementById('copy-notification');
            const shareNotification = document.getElementById('share-notification');
            const themeSwitch = document.getElementById('theme-switch');
            const privacyNotice = document.getElementById('privacy-notice');
            const closeNoticeBtn = document.getElementById('close-notice');
            const shareButton = document.getElementById('share-button');
            
            // 检查本地存储中的主题设置
            if (localStorage.getItem('theme') === 'dark') {
                document.documentElement.setAttribute('data-theme', 'dark');
                themeSwitch.checked = true;
            }
            
            // 主题切换功能
            themeSwitch.addEventListener('change', function() {
                if (this.checked) {
                    document.documentElement.setAttribute('data-theme', 'dark');
                    localStorage.setItem('theme', 'dark');
                } else {
                    document.documentElement.removeAttribute('data-theme');
                    localStorage.setItem('theme', 'light');
                }
            });
            
            // 隐私提示框关闭功能
            closeNoticeBtn.addEventListener('click', function() {
                privacyNotice.style.display = 'none';
                localStorage.setItem('privacyNoticeClosed', 'true');
            });
            
            // 检查是否需要显示隐私提示
            if (localStorage.getItem('privacyNoticeClosed') === 'true') {
                privacyNotice.style.display = 'none';
            }
            
            // MD5 哈希函数实现
            function md5(string) {
                function md5cycle(x, k) {
                    var a = x[0], b = x[1], c = x[2], d = x[3];
                    a = ff(a, b, c, d, k[0], 7, -680876936);
                    d = ff(d, a, b, c, k[1], 12, -389564586);
                    c = ff(c, d, a, b, k[2], 17, 606105819);
                    b = ff(b, c, d, a, k[3], 22, -1044525330);
                    a = ff(a, b, c, d, k[4], 7, -176418897);
                    d = ff(d, a, b, c, k[5], 12, 1200080426);
                    c = ff(c, d, a, b, k[6], 17, -1473231341);
                    b = ff(b, c, d, a, k[7], 22, -45705983);
                    a = ff(a, b, c, d, k[8], 7, 1770035416);
                    d = ff(d, a, b, c, k[9], 12, -1958414417);
                    c = ff(c, d, a, b, k[10], 17, -42063);
                    b = ff(b, c, d, a, k[11], 22, -1990404162);
                    a = ff(a, b, c, d, k[12], 7, 1804603682);
                    d = ff(d, a, b, c, k[13], 12, -40341101);
                    c = ff(c, d, a, b, k[14], 17, -1502002290);
                    b = ff(b, c, d, a, k[15], 22, 1236535329);
                    a = gg(a, b, c, d, k[1], 5, -165796510);
                    d = gg(d, a, b, c, k[6], 9, -1069501632);
                    c = gg(c, d, a, b, k[11], 14, 643717713);
                    b = gg(b, c, d, a, k[0], 20, -373897302);
                    a = gg(a, b, c, d, k[5], 5, -701558691);
                    d = gg(d, a, b, c, k[10], 9, 38016083);
                    c = gg(c, d, a, b, k[15], 14, -660478335);
                    b = gg(b, c, d, a, k[4], 20, -405537848);
                    a = gg(a, b, c, d, k[9], 5, 568446438);
                    d = gg(d, a, b, c, k[14], 9, -1019803690);
                    c = gg(c, d, a, b, k[3], 14, -187363961);
                    b = gg(b, c, d, a, k[8], 20, 1163531501);
                    a = gg(a, b, c, d, k[13], 5, -1444681467);
                    d = gg(d, a, b, c, k[2], 9, -51403784);
                    c = gg(c, d, a, b, k[7], 14, 1735328473);
                    b = gg(b, c, d, a, k[12], 20, -1926607734);
                    a = hh(a, b, c, d, k[5], 4, -378558);
                    d = hh(d, a, b, c, k[8], 11, -2022574463);
                    c = hh(c, d, a, b, k[11], 16, 1839030562);
                    b = hh(b, c, d, a, k[14], 23, -35309556);
                    a = hh(a, b, c, d, k[1], 4, -1530992060);
                    d = hh(d, a, b, c, k[4], 11, 1272893353);
                    c = hh(c, d, a, b, k[7], 16, -155497632);
                    b = hh(b, c, d, a, k[10], 23, -1094730640);
                    a = hh(a, b, c, d, k[13], 4, 681279174);
                    d = hh(d, a, b, c, k[0], 11, -358537222);
                    c = hh(c, d, a, b, k[3], 16, -722521979);
                    b = hh(b, c, d, a, k[6], 23, 76029189);
                    a = hh(a, b, c, d, k[9], 4, -640364487);
                    d = hh(d, a, b, c, k[12], 11, -421815835);
                    c = hh(c, d, a, b, k[15], 16, 530742520);
                    b = hh(b, c, d, a, k[2], 23, -995338651);
                    a = ii(a, b, c, d, k[0], 6, -198630844);
                    d = ii(d, a, b, c, k[7], 10, 1126891415);
                    c = ii(c, d, a, b, k[14], 15, -1416354905);
                    b = ii(b, c, d, a, k[5], 21, -57434055);
                    a = ii(a, b, c, d, k[12], 6, 1700485571);
                    d = ii(d, a, b, c, k[3], 10, -1894986606);
                    c = ii(c, d, a, b, k[10], 15, -1051523);
                    b = ii(b, c, d, a, k[1], 21, -2054922799);
                    a = ii(a, b, c, d, k[8], 6, 1873313359);
                    d = ii(d, a, b, c, k[15], 10, -30611744);
                    c = ii(c, d, a, b, k[6], 15, -1560198380);
                    b = ii(b, c, d, a, k[13], 21, 1309151649);
                    a = ii(a, b, c, d, k[4], 6, -145523070);
                    d = ii(d, a, b, c, k[11], 10, -1120210379);
                    c = ii(c, d, a, b, k[2], 15, 718787259);
                    b = ii(b, c, d, a, k[9], 21, -343485551);
                    x[0] = add32(a, x[0]);
                    x[1] = add32(b, x[1]);
                    x[2] = add32(c, x[2]);
                    x[3] = add32(d, x[3]);
                }
                function cmn(q, a, b, x, s, t) {
                    a = add32(add32(a, q), add32(x, t));
                    return add32((a << s) | (a >>> (32 - s)), b);
                }
                function ff(a, b, c, d, x, s, t) {
                    return cmn((b & c) | ((~b) & d), a, b, x, s, t);
                }
                function gg(a, b, c, d, x, s, t) {
                    return cmn((b & d) | (c & (~d)), a, b, x, s, t);
                }
                function hh(a, b, c, d, x, s, t) {
                    return cmn(b ^ c ^ d, a, b, x, s, t);
                }
                function ii(a, b, c, d, x, s, t) {
                    return cmn(c ^ (b | (~d)), a, b, x, s, t);
                }
                function md51(s) {
                    var n = s.length,
                        state = [1732584193, -271733879, -1732584194, 271733878], i;
                    for (i = 64; i <= s.length; i += 64) {
                        md5cycle(state, md5blk(s.substring(i - 64, i)));
                    }
                    s = s.substring(i - 64);
                    var tail = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
                    for (i = 0; i < s.length; i++)
                        tail[i >> 2] |= s.charCodeAt(i) << ((i % 4) << 3);
                    tail[i >> 2] |= 0x80 << ((i % 4) << 3);
                    if (i > 55) {
                        md5cycle(state, tail);
                        for (i = 0; i < 16; i++) tail[i] = 0;
                    }
                    tail[14] = n * 8;
                    md5cycle(state, tail);
                    return state;
                }
                function md5blk(s) {
                    var md5blks = [], i;
                    for (i = 0; i < 64; i += 4) {
                        md5blks[i >> 2] = s.charCodeAt(i)
                            + (s.charCodeAt(i + 1) << 8)
                            + (s.charCodeAt(i + 2) << 16)
                            + (s.charCodeAt(i + 3) << 24);
                    }
                    return md5blks;
                }
                var hex_chr = '0123456789abcdef'.split('');
                function rhex(n) {
                    var s = '', j = 0;
                    for (; j < 4; j++)
                        s += hex_chr[(n >> (j * 8 + 4)) & 0x0F]
                            + hex_chr[(n >> (j * 8)) & 0x0F];
                    return s;
                }
                function hex(x) {
                    for (var i = 0; i < x.length; i++)
                        x[i] = rhex(x[i]);
                    return x.join('');
                }
                function add32(a, b) {
                    return (a + b) & 0xFFFFFFFF;
                }
                return hex(md51(string));
            }
            
            // SHA-1 哈希函数实现
            function sha1(str) {
                function rotateLeft(n, s) {
                    var t4 = (n << s) | (n >>> (32 - s));
                    return t4;
                }
                function lsbHex(val) {
                    var str = "";
                    var i;
                    var vh;
                    var vl;
                    for (i = 0; i <= 6; i += 2) {
                        vh = (val >>> (i * 4 + 4)) & 0x0f;
                        vl = (val >>> (i * 4)) & 0x0f;
                        str += vh.toString(16) + vl.toString(16);
                    }
                    return str;
                }
                function cvtHex(val) {
                    var str = "";
                    var i;
                    var v;
                    for (i = 7; i >= 0; i--) {
                        v = (val >>> (i * 4)) & 0x0f;
                        str += v.toString(16);
                    }
                    return str;
                }
                function Utf8Encode(string) {
                    string = string.replace(/\r\n/g, "\n");
                    var utftext = "";
                    for (var n = 0; n < string.length; n++) {
                        var c = string.charCodeAt(n);
                        if (c < 128) {
                            utftext += String.fromCharCode(c);
                        } else if ((c > 127) && (c < 2048)) {
                            utftext += String.fromCharCode((c >> 6) | 192);
                            utftext += String.fromCharCode((c & 63) | 128);
                        } else {
                            utftext += String.fromCharCode((c >> 12) | 224);
                            utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                            utftext += String.fromCharCode((c & 63) | 128);
                        }
                    }
                    return utftext;
                }
                var blockstart;
                var i, j;
                var W = new Array(80);
                var H0 = 0x67452301;
                var H1 = 0xEFCDAB89;
                var H2 = 0x98BADCFE;
                var H3 = 0x10325476;
                var H4 = 0xC3D2E1F0;
                var A, B, C, D, E;
                var temp;
                str = Utf8Encode(str);
                var msg_len = str.length;
                var word_array = new Array();
                for (i = 0; i < msg_len - 3; i += 4) {
                    j = str.charCodeAt(i) << 24 | str.charCodeAt(i + 1) << 16 |
                        str.charCodeAt(i + 2) << 8 | str.charCodeAt(i + 3);
                    word_array.push(j);
                }
                switch (msg_len % 4) {
                    case 0:
                        i = 0x080000000;
                        break;
                    case 1:
                        i = str.charCodeAt(msg_len - 1) << 24 | 0x0800000;
                        break;
                    case 2:
                        i = str.charCodeAt(msg_len - 2) << 24 | str.charCodeAt(msg_len - 1) << 16 | 0x08000;
                        break;
                    case 3:
                        i = str.charCodeAt(msg_len - 3) << 24 | str.charCodeAt(msg_len - 2) << 16 | str.charCodeAt(msg_len - 1) << 8 | 0x80;
                        break;
                }
                word_array.push(i);
                while ((word_array.length % 16) != 14) word_array.push(0);
                word_array.push(msg_len >>> 29);
                word_array.push((msg_len << 3) & 0x0ffffffff);
                for (blockstart = 0; blockstart < word_array.length; blockstart += 16) {
                    for (i = 0; i < 16; i++) W[i] = word_array[blockstart + i];
                    for (i = 16; i <= 79; i++) W[i] = rotateLeft(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16], 1);
                    A = H0;
                    B = H1;
                    C = H2;
                    D = H3;
                    E = H4;
                    for (i = 0; i <= 19; i++) {
                        temp = (rotateLeft(A, 5) + ((B & C) | (~B & D)) + E + W[i] + 0x5A827999) & 0x0ffffffff;
                        E = D;
                        D = C;
                        C = rotateLeft(B, 30);
                        B = A;
                        A = temp;
                    }
                    for (i = 20; i <= 39; i++) {
                        temp = (rotateLeft(A, 5) + (B ^ C ^ D) + E + W[i] + 0x6ED9EBA1) & 0x0ffffffff;
                        E = D;
                        D = C;
                        C = rotateLeft(B, 30);
                        B = A;
                        A = temp;
                    }
                    for (i = 40; i <= 59; i++) {
                        temp = (rotateLeft(A, 5) + ((B & C) | (B & D) | (C & D)) + E + W[i] + 0x8F1BBCDC) & 0x0ffffffff;
                        E = D;
                        D = C;
                        C = rotateLeft(B, 30);
                        B = A;
                        A = temp;
                    }
                    for (i = 60; i <= 79; i++) {
                        temp = (rotateLeft(A, 5) + (B ^ C ^ D) + E + W[i] + 0xCA62C1D6) & 0x0ffffffff;
                        E = D;
                        D = C;
                        C = rotateLeft(B, 30);
                        B = A;
                        A = temp;
                    }
                    H0 = (H0 + A) & 0x0ffffffff;
                    H1 = (H1 + B) & 0x0ffffffff;
                    H2 = (H2 + C) & 0x0ffffffff;
                    H3 = (H3 + D) & 0x0ffffffff;
                    H4 = (H4 + E) & 0x0ffffffff;
                }
                var temp = cvtHex(H0) + cvtHex(H1) + cvtHex(H2) + cvtHex(H3) + cvtHex(H4);
                return temp.toLowerCase();
            }
            
            // 简单的 Crypt 实现（DES-based）
            function simpleCrypt(password, salt) {
                // 这是一个简化的 crypt 实现，实际应用中应该使用更完整的实现
                if (!salt) {
                    // 生成随机盐
                    const chars = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
                    salt = chars[Math.floor(Math.random() * chars.length)] + chars[Math.floor(Math.random() * chars.length)];
                }
                
                // 简化的 DES 加密模拟（实际应该使用真正的 DES）
                const hash = md5(salt + password).substring(0, 11);
                return salt + hash;
            }
            
            // 生成随机盐
            function generateSalt() {
                const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789./';
                let salt = '';
                for (let i = 0; i < 8; i++) {
                    salt += chars.charAt(Math.floor(Math.random() * chars.length));
                }
                return salt;
            }
            
            // htpasswd 密码生成功能
            function generateHtpasswd() {
                const username = usernameInput.value.trim();
                const password = passwordInput.value;
                const algorithm = algorithmSelect.value;
                
                if (!username) {
                    showResult('请输入用户名！', 'error');
                    return;
                }
                
                if (!password) {
                    showResult('请输入密码！', 'error');
                    return;
                }
                
                let hashedPassword = '';
                
                try {
                    switch (algorithm) {
                        case 'plain':
                            hashedPassword = password;
                            break;
                        case 'crypt':
                            hashedPassword = simpleCrypt(password);
                            break;
                        case 'md5':
                            const salt = generateSalt();
                            hashedPassword = '$apr1$' + salt + '$' + md5(password + salt).substring(0, 22);
                            break;
                        case 'sha1':
                            hashedPassword = '{SHA}' + btoa(sha1(password).match(/.{2}/g).map(byte => String.fromCharCode(parseInt(byte, 16))).join(''));
                            break;
                        default:
                            throw new Error('不支持的加密算法');
                    }
                    
                    const result = username + ':' + hashedPassword;
                    showResult(result, 'success');
                } catch (error) {
                    showResult(`生成失败: ${error.message}`, 'error');
                }
            }
            
            // 显示结果
            function showResult(message, type) {
                resultOutput.value = message;
                if (type === 'error') {
                    resultOutput.style.color = 'var(--error-color)';
                } else if (type === 'success') {
                    resultOutput.style.color = 'var(--success-color)';
                } else {
                    resultOutput.style.color = 'var(--text-color)';
                }
            }
            
            // 复制到剪贴板功能
            function copyToClipboard() {
                const result = resultOutput.value.trim();
                if (!result) {
                    showNotification(copyNotification, '没有可复制的内容！', true);
                    return;
                }
                
                const textarea = document.createElement('textarea');
                textarea.value = result;
                document.body.appendChild(textarea);
                textarea.select();
                document.execCommand('copy');
                document.body.removeChild(textarea);
                
                showNotification(copyNotification, '已复制到剪贴板！');
            }
            
            // 显示通知
            function showNotification(element, message, isError = false) {
                element.textContent = message;
                if (isError) {
                    element.style.backgroundColor = 'var(--error-color)';
                } else {
                    element.style.backgroundColor = 'var(--success-color)';
                }
                element.classList.add('show');
                setTimeout(() => {
                    element.classList.remove('show');
                }, 2000);
            }
            
            // 分享功能
            function shareURL() {
                const textarea = document.createElement('textarea');
                textarea.value = window.location.href;
                document.body.appendChild(textarea);
                textarea.select();
                document.execCommand('copy');
                document.body.removeChild(textarea);
                
                shareNotification.classList.add('show');
                setTimeout(() => {
                    shareNotification.classList.remove('show');
                }, 2000);
            }
            
            // 添加事件监听器
            generateButton.addEventListener('click', generateHtpasswd);
            copyButton.addEventListener('click', copyToClipboard);
            shareButton.addEventListener('click', shareURL);
            
            // 添加键盘快捷键支持
            passwordInput.addEventListener('keydown', function(e) {
                if (e.key === 'Enter') {
                    generateHtpasswd();
                }
            });
            
            // 双击结果区域复制内容
            resultOutput.addEventListener('dblclick', function() {
                if (this.value.trim()) {
                    copyToClipboard();
                }
            });
        });
    </script>
    
    <script>
        var _hmt = _hmt || [];
        (function() {
          var hm = document.createElement("script");
          hm.src = "https://hm.baidu.com/hm.js?3615c6485313357fe26e486bf42d9ec2";
          var s = document.getElementsByTagName("script")[0]; 
          s.parentNode.insertBefore(hm, s);
        })();
    </script>
</body>
</html>